package com.student.manager.servlet;

import com.student.manager.bean.Student;
import com.student.manager.service.StudentService;
import com.student.manager.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.List;

@WebServlet("/SearchStudentServlet")
public class SearchStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        try {

            String sname = request.getParameter("sname");
            String sgender = request.getParameter("sgender");

            System.out.println("sname:" + sname + "sgender:" + sgender  );

            StudentService service = new StudentServiceImpl();
            List<Student> students = service.searchStudent(sname, sgender);

            System.out.println("模糊查询学生数据");
            for (Student student : students) {
                System.out.println(student);
            }

            request.setAttribute("list" , students);

            request.getRequestDispatcher("list.jsp").forward(request, response);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
